package cn.cvs.config;

import cn.cvs.inteceptor.LoginInteceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(new LoginInteceptor());
        //设置要拦截那些URL
        interceptorRegistration.addPathPatterns("/**");
        //在上面拦截的基础上，放行哪些请求
        interceptorRegistration.excludePathPatterns("/","/toLogin","/login");
        //拦截器会拦截静态资源,所以要放行
        interceptorRegistration.excludePathPatterns("/statics/**");

    }
}
